import { fetcher } from '../fetcher'
import type { SuccessData } from '../types'
import type { MimoDecodeArgs, MimoPlotArgs } from './mimo'

export * from './mimo'
export * from './messages'

type JSONString = string

export type LabPayload<T> = {
  classID: number
  experimentID: number
  args: T
}
type LabData = SuccessData<{
  id: number
  content: JSONString
}>

export function ApiExecuteLab<T>(lab: string, body: LabPayload<T>) {
  return fetcher<LabData>(`/labs/${lab}`, {
    method: 'POST',
    body
  })
}

export function ApiExecuteMimoDecode(body: LabPayload<MimoDecodeArgs>) {
  return ApiExecuteLab('mimo-decode', body)
}
export function ApiExecuteMimoPlot(body: LabPayload<MimoPlotArgs>) {
  return ApiExecuteLab('mimo-plot', body)
}

export function ApiGetUploadURL(query: Omit<LabPayload<never>, 'args'>) {
  return fetcher<SuccessData<{ url: string }>>('/labs/upload', { query })
}
